﻿using AutoMapper;
using B.S.RbacData.Domain.Traceabilitys;
using B.S.RbacData.ErrorCode;
using B.S.RbacData.Infrastructure;
using B.S.RbacData.Read.API.Applications.Commands.Traceabilitys;
using B.S.RbacData.Read.API.Dtos.Traceabilitys;
using MediatR;

namespace B.S.RbacData.Read.API.Applications.CommandHandlters.Traceabilitys
{
    /// <summary>
    /// 获取商品命令处理
    /// </summary>
    public class GetAllGoodsCommandHandlter : IRequestHandler<GetAllGoodsCommand, ApiResult<List<GetAllGoodsDtos>>>
    {
        private readonly IBaseRepository<GoodsModel> goodsRep;
        private readonly IMapper mapper;

        public GetAllGoodsCommandHandlter(IBaseRepository<GoodsModel> GoodsRep,IMapper mapper)
        {
            goodsRep = GoodsRep;
            this.mapper = mapper;
        }


        public async Task<ApiResult<List<GetAllGoodsDtos>>> Handle(GetAllGoodsCommand request, CancellationToken cancellationToken)
        {



            //获取商品信息
            var GoodsList = goodsRep.GetAll().Where(x => !x.IsState&&!x.IsDeleted).ToList();



            return new ApiResult<List<GetAllGoodsDtos>>()
            {
                code = ResultEnumCode.Ok,
                data = mapper.Map<List<GetAllGoodsDtos>>(GoodsList),
                message = "获取成功"


            };

        }
    }
}
